/**
 * Created by Auser on 2016/10/13.
 */
$(function () {
    $('.ugo_register_mregist').click(function () {
        var $this=$(this);
        var phone=$('.ugo_register_mphone').val();
        var password=$('.ugo_register-mpassword').val();
        var rpassword=$('.ugo_register-mrpassword').val();
        $.ajax({
            type:'post',
            url:'text.php',
            dataType:'json',
            beforeSend: function () {
                var telText=/^1[0-9]{10}$/;
                if(!telText.test(phone)){
                    $('.telErr')
                        .html('手机号码不正确')
                        .fadeIn(500)
                        .delay(2000)
                        .fadeOut(500);
                    return false;
                }
                var pwdText=/\w{6,16}/;
                if(!pwdText.test(password)){
                    $('span.pasErr')
                        .html('密码不正确')
                        .fadeIn(500)
                        .delay(2000)
                        .fadeOut(500);
                    return false;
                }
            },
            success: function (data) {
                console.log(data);
            },
            error: function (data) {
                console.log(data);
            }
        })
    });
    $('button').click(function () {
        $btn=$(this);
        console.log(111);
        var telNum=$('.ugo_register_mphone').val();
        var phone=$('.ugo_register_mphone').val();
        var password=$('.ugo_register-mpassword').val();
        var rpassword=$('.ugo_register-mrpassword').val();
        $.ajax({
            type:"post",
            url:'test.php',
            dataType:'json',
            beforeSend: function () {
                if(!/^\d{10}$/.test(telNum)){
                    $('span.pasErr')
                        .html('密码不正确')
                        .fadeIn(500)
                        .delay(2000)
                        .fadeOut(500);
                    return false;
                }
                if($btn.addClass('disabled')) return false;
                $btn.addClass('disabled').html('正在发送中....');
            },
            success: function (data) {
                var time=parseInt(data.time)||60;
                var timer=setInterval(function () {
                    if(time===1){
                        $btn.removeClass('disabled').html('获取验证码');
                        clearInterval(timer);
                        return false;
                    }
                    time--;
                    $btn.html(time+"s后获取验证码")
                },1000);
            }
        });
    });
 });